<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="${ctx}/css/common.css" />
	<jsp:include page="../inc.jsp"></jsp:include>
	<jsp:include page="../head.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />
<title>订单查询-平台订单管理</title>
<style>
		body,div{
			margin:0 auto;
			padding:0 auto;
		}
		input{
			width:120px;
			height:18px;
			border:1px solid #77b2e0;
			border-radius: 3px;
		}
		select{
			height:20px;
			border:1px solid #77b2e0;
			border-radius: 3px;
		}
		.searchBox{
			width:1100px; 
			height:77px;
			margin:15px auto;
		}
		.searchBox li{
			float:left;
			margin-top:5px;
			margin-left:5px;
		}
		.tableOntab td{
			height:37px;
			border-right:none;
		}
		.tableOntab .borderNone{
			border-bottom:none;
		}
		.query{
			margin-left:5px;
		}
		/*使按钮居中*/
		.autoBoxTwo{
			width:180px;
			height:26px;
			margin:15px auto; 
		}
		input::-ms-clear{display:none;}
</style>

<script type="text/javascript">
	$(function(){
		//加载表格信息
		dataGrid = $('#orderTable').datagrid({
			url:'${ctx}/search/getPlatformList?orderType=0&temp='+Math.random(),
			striped : true,
			singleSelect : true,
			idField : 'flightIdList',
			pageList : [5,10,20],
			sortName:'orderCreateTime',
			sortOrder:'desc',
			method : 'get',
			toolbar:'#toolbar',
			pagination:true,
			
			columns:[[
			{
				width : '80',
				title : 'id',
				field : 'id',
				hidden : true,
				sortable : true
			},
			{
				width : '220',
				title : '订单号',
				align : 'center',
				field : 'airlineCode',
				sortable : true,
				formatter : function(value,row){
					var pssBusinessman=CommonConverter.toEmptyString(row.pssOrderNumber);
					var _orderNumber=CommonConverter.toEmptyString(row.orderNumber);
					var value='<p>平台：'+_orderNumber+'</p>'+'<p>供应商：'+pssBusinessman+'</p>';
					if(row.payTimeout==1){
						value='<p><img src="${ctx}/image/overtime.png"><span style="margin-left:2px;">平台：</span>'+_orderNumber+'</p>'+'<p>供应商：'+pssBusinessman+'</p>';
					};
					return value;
			}
			},{
				width : '80',
				title : '航班号',
				align : 'center',
				field : 'airlineId',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:60px;"><tr><td>'+((row.list))[0].airlineNumber+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:60px;"><tr><td>'+((row.list))[0].airlineNumber+'</td>'+'</tr><tr>'+'<td class="borderNone">'+((row.list))[1].airlineNumber+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '135',
				title : '出发',
				align : 'center',
				field : 'charterTypeStr',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].deptCity+'('+(row.list)[0].deptCode+')</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].deptCity+'('+(row.list)[0].deptCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].deptCity+'('+(row.list)[1].deptCode+')'+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '130',
				title : '到达',
				align : 'center',
				field : 'scheduleId',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].arrCity+'('+(row.list)[0].arrCode+')</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].arrCity+'('+(row.list)[0].arrCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].arrCity+'('+(row.list)[1].arrCode+')'+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '80',
				title : '出发日期',
				align : 'center',
				field : 'scheduleIdStr',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:80px;"><tr><td>'+(row.list)[0].deptDate+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:80px;"><tr><td>'+(row.list)[0].deptDate+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].deptDate+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '55',
				title : '出发时刻',
				align:'center',
				field : 'journeyType',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].deptTime)+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].deptTime)+'</td>'+'</tr><tr>'+'<td class="borderNone">'+CommonConverter.formatFlightTime((row.list)[1].deptTime)+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '55',
				title : '到达时刻',
				align:'center',
				field : 'toDate',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						
						if(row.list.length == 1){
							var backIntervalDay=(row.list)[0].intervalDay;
							var _backIntervalDay="";
							if (backIntervalDay >= 1){
								_backIntervalDay="+"+backIntervalDay;
							}; 
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].arrTime)+_backIntervalDay+'</td></tr></table>';
						}else if(row.list.length == 2){
							var toIntervalDay=(row.list)[0].intervalDay;
							var backIntervalDay=(row.list)[1].intervalDay;
							var _toIntervalDay="";
							var _backIntervalDay="";
							if (toIntervalDay >= 1){
								_toIntervalDay="+"+toIntervalDay;
							}; 
							if (backIntervalDay >= 1){
								_backIntervalDay="+"+backIntervalDay;
							}; 
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].arrTime)+_toIntervalDay+
							'</td>'+'</tr><tr>'+'<td class="borderNone">'+CommonConverter.formatFlightTime((row.list)[1].arrTime)+_backIntervalDay+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '100',
				title : '供应商/采购商',
				align:'center',
				field : 'backDate',
				formatter : function(value,row){
					var value='<p>卖：'+CommonConverter.toEmptyString(row.sellerName)+'</p>'+'<p>买：'+CommonConverter.toEmptyString(row.buyerName)+'</p>'+
							  '<p>真实姓名：'+CommonConverter.toEmptyString(row.createuserName)+'</p>'+'<p>联系电话：'+CommonConverter.toEmptyString(row.mobile)+'</p>';
					return value;
				}
			},{
				width : '50',
				title : '数量',
				align:'center',
				field : 'purchQuantity',
			},{
				width : '160',
				title : '时间点',
				align:'center',
				field : 'seatClassStr',
				formatter : function(value,row){
					var value='<p>下单：'+row.orderCreateTime+'</p>'+'<p>支付：'+CommonConverter.toEmptyString(row.payTime)+'</p>'+
							  '<p>名单：'+CommonConverter.toEmptyString(row.passengerUptime)+'</p>'+
							  '<p>出票：'+CommonConverter.toEmptyString(row.ticketOuttime)+'</p>';
					return value;
				}
			},{
				width : '130',
				title : '支付明细',
				align:'center',
				field : 'totalStock',
				formatter : function(value,row){
					var shouldReceiveMoney=row.sellingPrice*row.purchQuantity;
					var brokerage=shouldReceiveMoney*row.charges;
					var shouldPayMoney=shouldReceiveMoney-brokerage;
					//console.log(shouldReceiveMoney+"-"+brokerage+"="+shouldPayMoney);
					var value='<p>应收金额：<span style="color:#3989c8;">￥'+shouldReceiveMoney+'</span></p>'+
							  '<p>佣金：<span style="color:#fc931d">￥'+brokerage+'</span></p>'+'<p> 应付金额：<span style="color:#f80000;">￥'+shouldPayMoney+'</span></p>';
					return value;
				}
			},{
				width : '120',
				title : '状态',
				align:'center',
				field : 'placeHolder',
				formatter : function(value,row){
					var orderStatus=CommonConverter.toOrderBizStatusStr(row.orderStatus);
					var financeStatus=CommonConverter.toOrderPayStatusStr(row.financeStatus);
					var value='<p>业务状态：'+orderStatus+'</p>'+'<p>财务状态：'+financeStatus+'</p>';
					return value;
				}
			},{
				title : '操作',
				align:'center',
				field : 'fareSaleStr',
				formatter:function(value,row){
					var str = '<div class="autoBoxTwo"><span class="mynewBtn" onclick=detail("'+row.orderNumber+'")>查看详情</span>'+'<span class="mynewBtn" onclick=log("'+row.orderNumber+'")>查看日志</span></div>';
					if(row.orderStatus==0){
						str = '<span class="mynewBtn" onclick=detail("'+row.orderNumber+'")>查看详情</span>'+'<span class="mynewBtn" onclick=log("'+row.orderNumber+'")>查看日志</span>'+'<span class="mynewBtn" onclick=cancel("'+row.orderNumber+'")>取消订单';
					};
					return str;
				}
			}
			] ]
		});
		//点击查询 重新加载列表
		$("#query").click(function(){
			//出发到达城市清空处理
			alsoempty($("#homecity_name"),$("#_startCity"));
			alsoempty($("#getcity_name"),$("#_endCity"));
			//获取参数
			var orderNumber=$("#_orderNumber").val();
			var pssOrderNumber=$("#_pssNumber").val();
			var orderStatus=$("#orderStatus").val();
			var toStartAirportCode=$("#_startCity").val();
			var toEndAirportCode=$("#_endCity").val();
			var toStartDate=$("#_startTime").datebox('getValue');
			var toEndDate=$("#_endTime").datebox('getValue');
			var buyerName=$("#buyerName").val();
			var sellerName=$("#sellerName").val();
			var financeStatus=$("#financeStatus").val();
			if(typeof(toStartAirportCode) == 'undefined'){
				toStartAirportCode = "";
			}
			if(typeof(toEndAirportCode) == 'undefined'){
				toEndAirportCode = "";
			}
			$('#orderTable').datagrid('load',{"orderNumber":orderNumber,"pssOrderNumber":pssOrderNumber,"orderStatus":orderStatus,"toStartAirportCode":toStartAirportCode,"toEndAirportCode":toEndAirportCode,"toStartDate":toStartDate,"toEndDate":toEndDate,"buyerName":buyerName,"sellerName":sellerName,"financeStatus":financeStatus,"temp":Math.random()});
			//$('#orderTable').datagrid('load',queryVo);
		});
		
	});
	//查看详情
	function detail(orderNumber){
		layer.open({
			type: 2,
			title: ['订单详情','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.5,
			area: ['1200px', '500px'],
			content: ['${ctx}/nporder/detail/'+orderNumber, 'yes'],
			success: function(layero, index){
			  layer.full(index);
			},
			end:function(){
			}
		});
	}
	//查看日志
	function log(orderNumber){
		layer.open({
			type: 2,
			title: ['订单操作记录','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.5,
			area: ['750px', '450px'],
			content: ['${ctx}/nporder/logs/'+orderNumber, 'no'],
			success: function(layero, index){
			},
			end:function(){
			}
		});
	};
	//取消订单
	function cancel(orderNumber){
		layer.confirm("确认要取消订单【"+orderNumber+"】吗？"
			, {title:['取消订单','background-color:#00B2EE; color:#fff;'],area: ['400px', '150px']}
			, function(index){
				layer.open({
					type: 2,
					title: ['取消订单','background-color:#00B2EE; color:#fff;'],
					shadeClose: true,
					shade: 0.5,
					area: ['500px', '380px'],
					content: ['${ctx}/nporder/cancel/'+orderNumber, 'no'],
					success: function(layero, index){
					},
					end:function(){
					}
				});
				  
				layer.close(index);
			}
		);
	};
	//如果为空  对应的文本框为空
	function alsoempty(a,b){
		if(a.val() == "中文/拼音"){
			b.val("");
		};
	};
</script>
</head>
<body>
	<div>
		 <div>
			<ul class="searchBox">
					<li>平台订单号：<input  id="_orderNumber" name="charterType" class="easyui-textbox"/></li>
					<li>供应商订单号：<input  id="_pssNumber" name="charterType" class="easyui-textbox"/></li>
					<li>采购商：<input  id="buyerName" name="charterType" class="easyui-textbox"/></li>
					<li>供应商：<input  id="sellerName" name="charterType" class="easyui-textbox"/></li>
					<li>
						出发时间 ：<input class="easyui-datebox" id="_startTime" style="width: 120px" />
						至<input class="easyui-datebox" id="_endTime" style="width: 120px" /></li>
					<li>
						业务状态：
						<select id="orderStatus" style="width: 73px;">
							<option value="-1">所有订单</option>
							<option value="0">待支付</option>
							<option value="2">待出票</option>
							<option value="3">出票中</option>
							<option value="4">出票完成</option>
							<option value="5">已取消</option>
						</select>
					</li>
					<li>
						财务状态：
						<select id="financeStatus" style="width: 83px;">
							<option value="-1">全部</option>
							<option value="1">收款待审核</option>
							<option value="2">已收款</option>
							<option value="3">待提现</option>
							<option value="4">提现待审核</option>
							<option value="5">提现待支付</option>
							<option value="6">已付款</option>
						</select>
					</li>
					<li>出发城市：
					<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
					<input id="_startCity" name="_startCity" type="hidden" value="" />
					</li>
					<li>到达城市：
					<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
					<input id="_endCity" name="_endCity" type="hidden" value="" />
					</li>
					<li><button class='query' id="query">查询</button></li>
				</ul>
		 </div>
		 <div>
			<table id="orderTable"  class="easyui-datagrid"></table>
		 </div>
	</div>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>